<?php  
class ControllerCategoryList extends Controller {
	public function index() {
		$this->document->setTitle('目录列表');
		$this->document->setDescription($this->config->get('config_meta_description'));

		$this->data['heading_title'] = '目录列表';
        
        $this->load->model('category');
        $results = $this->model_category->getCategories();
        $category_total = $this->model_category->getTotalCategories();
        
        foreach ($results as $result) {
            if ($result['status']) {
                $this->data['categories'][] = array(
                    'id'    => $result['cat_id'],
                    'name'  => $result['cat_name'],
                    'total' => $category_total
                );
            }
        }
        

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . 'category/list.tpl')) {
			$this->template = $this->config->get('config_template') . 'category/list.tpl';
		} else {
			$this->template = 'category/list.tpl';
		}
		
		$this->children = array(
			'common/footer',
			'common/header'
		);
		$this->response->setOutput($this->render());
	}
    
    public function update(){
                
        $json = array();
        if (isset($this->request->get['cat_id'])) 
        {
            $cat_id = $this->request->get['cat_id'];
        }
        
        $this->load->model('category');
        $cat_name = $this->model_category->getCatName($cat_id);
        if($cat_name)
        {
            $json['success'] = '目录更新成功';
        }
        
        $this->load->library('json');
		$this->response->setOutput(Json::encode($json));
    }
}
?>